package almata.dai.jhuguet;

import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ConnectorBD {

	private String url;
	private Connection conn;
	private String server="localhost", bd="centreesportiu";
	private int port=3306;

	
	public ConnectorBD(){
		this.url = "jdbc:mysql://"+server+":" + port + "/"+bd;
		try{
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * Gets JDBC connection from the connection pool.
	 * 
	 * @return the JDBC connection	
	 * 
	 */
	
	protected Connection getConnection() throws Exception{
		try{
			conn = DriverManager.getConnection(url, "root", "");
			return conn;

		}catch(Exception e){
			System.err.println("Couldn't get connection!");
			e.printStackTrace();
			throw e;
		}
	}
	
	protected void closeConnection(Connection conn) throws Exception{
		try{
			conn.close();
		}catch(Exception e){
			System.err.println("Couldn't close connection!");
			e.printStackTrace();
			throw e;
		}
	}
		
}